﻿namespace eslib.FileManageLib
{
    /// <summary>
    /// 文件系统抽象 
    /// </summary>
    public abstract class FileBase
    {
        /// <summary>
        /// 文件/目录名称。不应包括路径
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 父目录
        /// </summary>
        public FileBase? Parent { get; set; }

        /// <summary>
        /// 文件路径
        /// </summary>
        public string FilePath
        {
            get
            {
                string path = Name;
                if (Parent != null)
                {
                    path = Path.Combine(Parent.FilePath, path);
                }
                return path;
            }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="parent">父目录,为null表示根目录</param>
        protected FileBase(string name, FileBase? parent)
        {
            Name = name;
            Parent = parent;
        }



        #region 文件系统操作

        public abstract void Delete();

        /// <summary>
        /// 移动到dir
        /// </summary>
        /// <param name="target"></param>
        public abstract FileBase MoveTo(Dir target);

        /// <summary>
        /// 复制到dir
        /// </summary>
        /// <param name="target"></param>
        public abstract FileBase CopyTo(Dir target);


        /// <summary>
        /// 重命名
        /// </summary>
        /// <param name="name"></param>
        public abstract void ReName(string name);

        #endregion


        public override string? ToString()
        {
            return $"[{this.GetType()}]{FilePath}";
        }
    }
}